﻿(function () {
    var userFriends = new WinJS.Binding.List([]);

    var getUserFriends = function () {
        var persister = Persister.getPersister();

        persister.user.getFriends().then(function (data) {
            var friendsList = JSON.parse(data.responseText);

            var currentCount = userFriends.dataSource.list.length;
            userFriends.dataSource.list.splice(0, currentCount);

            for (var i = 0; i < friendsList.length; i++) {
                userFriends.push(friendsList[i]);
            }
        }, function (error) {
            var msg = new Windows.UI.Popups.MessageDialog(error.statusText);
            msg.showAsync();
        });
    }

    WinJS.Namespace.define("ViewModels", {
        userFriends: userFriends,
        getUserFriends: getUserFriends
    });
}());